/************************
Name : TestDatabaseCMS
Created By : dthekumparampil
Created Date : Jan 27, 2013
Description : This is not a TEST class, but is used by test classes to created dataset to do testing.

************************/



public class TestDatabaseCMS {
	
	public static Account createAccountForTesting() {
		
		/*Getting RecordType IDs*/
		String accountRecordType = Schema.Sobjecttype.Account.getRecordTypeInfosByName().get('West - Student Account').getRecordTypeId();
		
		/*Creating Account*/
		Account testAccountDatabase = new Account(FirstName= 'CreateCase', LastName = 'TestUser', Personal_Email__pc ='abcd1@ddd.com', 
    	BillingState = 'Arizona', BillingCountry = 'USA',Status__c = 'Prospect', RecordTypeId=accountRecordType);//, Account_Id__c = 'A0001' );
    	insert testAccountDatabase;
    	
    	testAccountDatabase = [select FirstName, LastName, Personal_Email__pc, BillingState, BillingCountry, Status__c, RecordTypeId, Account_Id__c
    	  from Account where id=:testAccountDatabase.id];
    	return testAccountDatabase;		
    }
    
    public static Lead createLeadForTesting(){
    	/*Getting RecordType IDs*/
    	String leadRecordType = Schema.Sobjecttype.Lead.getRecordTypeInfosByName().get('West - Prospective Student').getRecordTypeId();
    	String programRecordType = Schema.Sobjecttype.Program__c.getRecordTypeInfosByName().get('West - Program').getRecordTypeId();
    	
    	/*Creating Program*/
    	Program__c testProgramDatabase = new Program__C(name='Bachelor of Science in Accounting', RecordTypeId=programRecordType );
    	insert testProgramDatabase;
    	
    	/*Creating Lead*/
    	Lead testLeadDatabase = new Lead(FirstName = 'CreateCase',LastName='TestLead', Personal_Email__c='ssss@yyyy.com', IsConverted=false,
    	State='AZ',Country='USA',Program__c=testProgramDatabase.id, RecordTypeId=leadRecordType, Anticipated_Start_Date__c=Date.today().addDays(30),
    	Home_Phone__c='(234) 234-3454');
    	insert testLeadDatabase;
    	
    	testLeadDatabase = [select FirstName, LastName, Personal_Email__c, IsConverted,State,Country,Program__c, RecordTypeId,
    	Anticipated_Start_Date__c, Home_Phone__c, Lead_ID__c from Lead where id=:testLeadDatabase.id];
    	return testLeadDatabase;
    }
    
    public static Program__c createProgramForTesting(){
    	
    	/****Accessing RecordTypeInfo****/
    	String programRecordType = Schema.Sobjecttype.Program__c.getRecordTypeInfosByName().get('West - Program').getRecordTypeId();
    	
    	/****Creating Program****/
    	Program__c testProgramDatabase = new Program__C(name='Bachelor of Science in Accounting', RecordTypeId=programRecordType );
    	insert testProgramDatabase;
    	
    	return testProgramDatabase;
    }
    
    public static West_Case_Names__c createWestCaseNames (){
    	
    	try{
	    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
	    	insert objWestSecurityExtenstion;	
	    }Catch(Exception Ex){
	           System.Debug('---exp--' +  Ex.getmessage());
	       
	    }
		
    	/*Creating West_Case_Names__c values*/
		West_Case_Names__c newRecord = new West_Case_Names__c(name='Academic Probation', West_Case_Name_Category__c='Academic', West_Case_Name_Activity__c='Program', 
		West_Case_Group__c='Administration', West_Queue_Name__c='CM - Queue 19', West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
		insert newRecord;
		return newRecord;
    }
    
    public static West_Case_Names__c createMiscWestCaseNames (){
    	try{
	    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
	    	insert objWestSecurityExtenstion;	
	    }Catch(Exception Ex){
	           System.Debug('---exp--' +  Ex.getmessage());
	       
	    }
    	
    	/*Creating West_Case_Names__c values*/
		West_Case_Names__c newRecord = new West_Case_Names__c(name='Miscellaneous', West_Case_Name_Category__c='General', West_Case_Name_Activity__c='Miscellaneous', 
		West_Case_Group__c='Student', West_Queue_Name__c='CM - Queue 1', West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
		insert newRecord;
		return newRecord;
    }
    
    public static West_Webform_Picklist__c createWestWebformPicklist (){
    	
    	/*Creating West_Webform_Picklist__c values*/
		West_Webform_Picklist__c newRecord = new West_Webform_Picklist__c(name='Application Information', Picklist_Value__c='Application Information', URL_Mode__c='Secure');
		insert newRecord;
		West_Webform_Picklist__c newRecord2 = new West_Webform_Picklist__c(name='Enrollment Information', Picklist_Value__c='Enrollment Information', URL_Mode__c='Unsecure');
		insert newRecord2;
		return newRecord;
	}
    
    public static BusinessHours createWestBusinessHour(){
    	Time startTime = Time.newInstance(8, 0, 0, 0);
    	Time endtime = Time.newInstance(17, 0, 0, 0);
    	BusinessHours businesshour = new BusinessHours(name='West Phoenix Business Hours',IsActive=true, IsDefault=false, MondayStartTime=startTime, MondayEndTime=endTime, TuesdayStartTime=startTime, TuesdayEndTime=endTime, WednesdayStartTime=startTime, WednesdayEndTime=endTime, ThursdayStartTime=startTime, ThursdayEndTime=endTime, FridayStartTime=startTime, FridayEndTime=endTime, SaturdayStartTime=startTime, SaturdayEndTime=endTime, TimeZoneSidKey='America/Phoenix');
    	//insert businesshour;
    	return businesshour;
    }
    
    /*Changes made by Kalyani to add Test Case*/
    public static Case createCaseForTesting(){
    	try{
	    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
	    	insert objWestSecurityExtenstion;	
	    }Catch(Exception Ex){
	           System.Debug('---exp--' +  Ex.getmessage());
	       
	    }
	    Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
    	/*Getting RecordType IDs*/
		String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
		/*Creating Case record*/
		West_Case_Names__c testCaseNames = createWestCaseNames();
    	Case newRecord = new Case(AccountId = accountAssociatedWithCase.id, RecordTypeId=caseRecordType, Case_Name__c = testCaseNames.Name, Status = 'New', Origin='Phone', Description = '3 Fs Test Description' );
    	insert newRecord;
    	newRecord = [SELECT Queue_Name__c, CaseNumber, Priority, Group__c, Category__c, Activity__c, West_Case_Deadline__c FROM Case
         						  WHERE Id = :newRecord.Id];
    	return newRecord;
    }
    
   public static Case updateCaseForTesting(){
   		try{
	    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
	    	insert objWestSecurityExtenstion;	
	    }Catch(Exception Ex){
	           System.Debug('---exp--' +  Ex.getmessage());
	       
	    }
	    Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
   		/*Getting RecordType IDs*/
		String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
		/*Creating Case record*/
		West_Case_Names__c testUpdateCaseNames = createWestCaseNames();
		West_Case_Names__c testAfterUpdateCaseNames = createMiscWestCaseNames();
    	Case newRecord = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId=caseRecordType, Case_Name__c = testUpdateCaseNames.Name, Status = 'New', Origin='Phone', Description = '3 Fs Test Description' );
    	insert newRecord;
    	newRecord.Case_Name__c = testAfterUpdateCaseNames.Name;
    	update newRecord;
    	newRecord = [SELECT Queue_Name__c, CaseNumber, Priority, Group__c, Category__c, Activity__c, West_Case_Deadline__c FROM Case
         						  WHERE Id = :newRecord.Id];
    	return newRecord;
   } 
  
  public static Case caseStatusTesting(){
  		Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
  		/*Getting RecordType IDs*/
		String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
		/*Creating Case record*/
		West_Case_Names__c testCaseNames = createWestCaseNames();
    	Case newRecord = new Case(AccountID=accountAssociatedWithCase.id,RecordTypeId=caseRecordType, Case_Name__c = testCaseNames.Name, Status = 'New', Origin='Phone', Description = '3 Fs Test Description' );
    	insert newRecord;
    	newRecord.Manual_status_change__c = true;
    	newRecord.Status= 'Transferred';
    	update newRecord;
    	newRecord = [SELECT Queue_Name__c, CaseNumber, Priority, Group__c, Category__c, Activity__c, West_Case_Deadline__c FROM Case
         						  WHERE Id = :newRecord.Id];
    	return newRecord;
  } 
   public static West_Case_Names__c createWestCaseNamesAutoInitial (){
    	
    	/*Creating West_Case_Names__c values*/
		West_Case_Names__c newRecord = new West_Case_Names__c(name='12 no activity', West_Case_Name_Category__c='General', West_Case_Name_Activity__c='Call', 
		West_Case_Group__c='Student', West_Queue_Name__c='CM - Queue 1', West_Case_Priority__c='4', West_Case_Type_Deadline__c=1, West_Case_Auto_Initial__c=true);
		insert newRecord;
		return newRecord;
    }
    
     public static West_Case_Type__c createWestCaseTypes(){
    	
    	/*Creating West_Case_Type__c values*/
		West_Case_Type__c newRecord = new West_Case_Type__c(West_Case_Type_Field__c='12 no activity', West_Case_Type_Category__c='General', West_Case_Type_Activity__c='Call', 
		West_Case_Type_Group__c='Student',Initial_Response_Template_Body__c='A new case has been created in reference with "{!Case.Subject}". Please contact support to know status of the case or for any additional questions.');
		insert newRecord;
		return newRecord;
    } 
 public static Case caseAutoInitialTesting(){
 	/*West Security Extensions*/
 	try{
    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
    	insert objWestSecurityExtenstion;	
    }Catch(Exception Ex){
           System.Debug('---exp--' +  Ex.getmessage());
       
    }
    Account accountAssociatedWithCase=new Account(Name='TestAccount');
    insert accountAssociatedWithCase;
 	/*Getting RecordType IDs*/
		String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
	/*Creating Case record*/
	West_Case_Names__c testAutoName = createWestCaseNamesAutoInitial();
	 Case newRecord = new Case(AccountId = accountAssociatedWithCase.id,RecordTypeId = caseRecordType, Status = 'New',  Case_Name__c = testAutoName.Name,
        Subject = 'Need help -No activity for 12 days', Description = 'Need help -No activity for 12 days', Origin = 'Phone');
	createWestCaseTypes();
	insert newRecord;
	//newRecord.Manual_status_change__c = true;
    //newRecord.Status= 'Closed';	
   // update newRecord;
    
	newRecord  = [SELECT Queue_Name__c, CaseNumber,Initial_Response_Template_Body__c, Priority, Group__c, Category__c, Activity__c, West_Case_Deadline__c FROM Case
         						  WHERE Id = :newRecord.Id ];
	System.debug('New Record is'+newRecord);
	return newRecord;
 } 
}